#include "PersonTest.h"
#include "common/Date.h"
#include <string>

namespace etu {

    using etu::common::Date;

void PersonTest::setUp() {
    Date birthDate(2010, 03, 28);
    Date deathDate = Date::unkown();

    this->person = new Person("FirstName", "LastName", etu::genealogy_tree::UNKNOWN_GENDER,
            birthDate, deathDate);
}

void PersonTest::tearDown() {
    delete this->person;
}

void PersonTest::unknownPersonTest() {
    Person unknownPerson = Person::unknown();

    CPPUNIT_ASSERT_EQUAL(true, Person::isUnkownPerson(unknownPerson));
    CPPUNIT_ASSERT_EQUAL(false, Person::isUnkownPerson(* this->person));
}

void PersonTest::contentsTest() {
    std::string firstName = "FirstName";
    std::string lastName = "LastName";

    CPPUNIT_ASSERT_EQUAL(firstName, this->person->getFirstName());
    CPPUNIT_ASSERT_EQUAL(lastName, this->person->getLastName());
    CPPUNIT_ASSERT_EQUAL(etu::genealogy_tree::UNKNOWN_GENDER, this->person->getGender());
    CPPUNIT_ASSERT_EQUAL(2010, this->person->getBirthDate().getYear());
    CPPUNIT_ASSERT_EQUAL(3, this->person->getBirthDate().getMonth());
    CPPUNIT_ASSERT_EQUAL(28, this->person->getBirthDate().getDay());
    CPPUNIT_ASSERT_EQUAL(true, Date::isUnkown(this->person->getDeathDate()));
}

void PersonTest::serializationTest() {
    Person srcPerson = * this->person;
    std::ostringstream oss;
    std::istringstream iss;

    oss << srcPerson;
    iss.str(oss.str());

    Person* dstPerson = new Person("Name", "LastName", etu::genealogy_tree::UNKNOWN_GENDER,
            Date::unkown(), Date::unkown());
    iss >> (* dstPerson);

    CPPUNIT_ASSERT_EQUAL(true, (* dstPerson) == srcPerson);
}

}
